package com.admin.kotlintest.adapter

import android.content.Context
import android.widget.CheckBox
import com.admin.kotlintest.R
import com.admin.kotlintest.base.AdapterHolder
import com.admin.kotlintest.base.CurrencyAdapter
import com.admin.kotlintest.bean.Car
import com.admin.kotlintest.custome.ScrollListView

/**
 * Created by 吴昶 on 2018/4/19.
 */
class ChoseCarListAdapter(context: Context,layoutId:Int,data:MutableList<Car>?,var scrollView: ScrollListView,var listener:CarItemCilckListener?):CurrencyAdapter<Car>(context,layoutId,data){

    var boxlist=HashMap<Int,CheckBox?>()
    var chosed=-1

    init {
        scrollView.adapter=this
        scrollView.setOnItemClickListener { parent, view, position, id ->
            var box=boxlist[position]
            box!!.isChecked = !box.isChecked
        }
    }

    override fun convert(holder: AdapterHolder, item: Car, position: Int) {
        holder.setTextViewText(R.id.tv_car_list_number,item.carNumber.toString())
        holder.setTextViewText(R.id.tv_car_list_driver,item.driver!!.username)
        var box=holder.getCheckBox(R.id.cb_car_chose)
        boxlist[position] = box
        box?.let {
            box.setOnCheckedChangeListener { buttonView, isChecked ->
                listener!!.ItemClickListener(item,box,position)
            }
        }
    }

    interface CarItemCilckListener{
        fun ItemClickListener(item: Car,box:CheckBox?,position: Int)
    }
}